# 物品模型
from datetime import datetime
from extensions import db
from models.user import User

class Item(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    description = db.Column(db.Text)
    category = db.Column(db.String(50))  # 添加分类字段
    price = db.Column(db.Float)  # 添加价格字段
    stock = db.Column(db.Integer, default=0)  # 添加库存字段
    status = db.Column(db.String(20), default='在售')  # 添加状态字段
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship('User', backref=db.backref('items', lazy=True))

    def __repr__(self):
        return f'<Item {self.name}>'